<?php
include_once ("db_mysql.php");
$check = "checked";
$_POST["von"] = 1;
$_POST["bis"] = 2;
$_POST["friendID"] = '171970728';
$viewProfile="http://friends.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=";
$viewFriends="http://friends.myspace.com/index.cfm?fuseaction=user.viewfriends&friendID=";

		$strProfile=file($viewFriends.$_POST["friendID"]);
        for ($z = 0; $z < sizeof($strProfile); $z++)
        {
            $strArrayProfile.=$strProfile[$z];
        }
        preg_match_all('#<option selected=\"selected\" value=\"all\">(.+)<\/option>#isU', $strArrayProfile, $detfr[1]);

        preg_match_all('#von <a href=\"javascript: GotoPage((.+));\" class="pagingLink"#isU', $strArrayProfile, $detfr[2]);

   // Alle Seiten durchlaufen
for ($huindex = $_POST["von"]; $huindex <= $_POST["bis"]; $huindex++)
{
        $strArray="";
        
        if ($check == "checked") {
        	switch ($huindex) {
        		case 1:
		        	$str=file("http://friends.myspace.com/index.cfm?fuseaction=user.viewfriends&friendID=".$_POST["friendID"]."&view=New");
        		break;
        		case 2:
		        	$str=file("http://friends.myspace.com/index.cfm?fuseaction=user.viewfriends&friendID=".$_POST["friendID"]."&view=New&p=1&j=1");
        		break;
        		default:
        			;
        		break;
        	}
        }else{
        	$str=file("http://friends.myspace.com/index.cfm?fuseaction=user.viewfriends&friendID=".$_POST["friendID"]."&p=1&j=".$huindex);
        	//echo "http://friends.myspace.com/index.cfm?fuseaction=user.viewfriends&friendID=".$_POST["friendID"]."&p=1&j=".$huindex."<br>";
        }
        for ($y = 0; $y < sizeof($str); $y++)
        {
                $strArray.=$str[$y];
        }

        preg_match_all('#<div friendid=(.+)/li>#isU', $strArray, $det_arr);
        $detail = array();
        for ($index = 0; $index < count($det_arr[0]); $index++)
        {
                preg_match_all('#<div friendid=\"(.+)\" class=\"friendHelperBox#isU', $det_arr[0][$index], $det[$index]);

                $detail[$index]['id']=$det[$index][1];
                
                //preg_match_all('#class=\"msProfileLink\" title=\"(.+)\" style=#isU', $det_arr[0][$index], $det[$index]);
				preg_match_all('#class=\"msProfileTextLink\" title=\"(.+)<\/a><\/div><span class=\"msProfileLink#isU', $det_arr[0][$index], $det[$index]);
                
				$str_title = explode("\">", $det[$index][1][0]);
                $detail[$index]['title']=$str_title[0];
				
                preg_match_all('#spacer.gif\" source=\"(.+)\" alt=#isU', $det_arr[0][$index], $det[$index]);
                $detail[$index]['img']=$det[$index][1];
                $strArrayProfile = "";

        }


        for ($i = 0; $i < sizeof($detail); $i++)
        {
			if ($_POST["friendID"] == '171970728') {
	            $sql = "INSERT INTO friends (id, name, pic) VALUES ('".$detail[$i]['id'][0]."', '".$detail[$i]['title']."', '".$detail[$i]['img'][0]."')";
			}else{
	            $sql = "INSERT INTO pool (id, name, pic, owner) VALUES ('".$detail[$i]['id'][0]."', '".$detail[$i]['title']."', '".$detail[$i]['img'][0]."', '".$_POST["friendID"]."')";
			}
            dbquery($sql); 

        }

}
?>